package cn.edu.xmu.oomall.aftersales.service;

import cn.edu.xmu.javaee.core.exception.BusinessException;
import cn.edu.xmu.javaee.core.model.ReturnNo;
import cn.edu.xmu.oomall.aftersales.dao.AfterSalesDao;
import cn.edu.xmu.oomall.aftersales.dao.OrderItemDao;
import cn.edu.xmu.oomall.aftersales.dao.bo.AfterSales;
import cn.edu.xmu.oomall.aftersales.controller.vo.AfterSalesDto;
import cn.edu.xmu.javaee.core.model.dto.UserDto;
import cn.edu.xmu.oomall.aftersales.dao.bo.OrderItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional(propagation = Propagation.REQUIRED)
public class AfterSalesService {

    private static final Logger logger = LoggerFactory.getLogger(AfterSalesService.class);

    private final AfterSalesDao afterSalesDao;
    private final OrderItemDao orderItemDao;

    @Autowired
    public AfterSalesService(AfterSalesDao afterSalesDao, OrderItemDao orderItemDao) {
        this.afterSalesDao = afterSalesDao;
        this.orderItemDao = orderItemDao;
    }
    /**
     * 创建新的售后
     *
     * @param id orderitem id
     * @param afterSales 售后数值对象
     * @param user 登录用户
     * @return
     */
    public AfterSales applyForAfterSales(Long id, AfterSales afterSales, UserDto user) {
        orderItem orderItem = this.orderItemDao.findById(id);
        return orderItem.createAfterSales(afterSales, user);
    }
}
